<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>OpenLayers External Map Test</title>
  <style>
    html, body, #map {
      height: 100%;
      margin: 0;
      padding: 0;
    }
  </style>
</head>
<body>
  <div id="map"></div>
  <script>
    function makePrimary(event) {
      Object.defineProperty(event, 'isPrimary', {
        writable: false,
        value: true,
      });
      return event;
    }
    window.addEventListener('message', (e) => {
      const viewport = document.querySelector('div.ol-viewport');
      viewport.dispatchEvent(makePrimary(new PointerEvent('pointerdown', {
        clientX: 10,
        clientY: 10,
      })));
    });
  </script>
</body>
</html>